﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpUtils
{
    class CommonEqualityComparer<T, V> : IEqualityComparer<T>
    {
        private readonly Func<T, V> _keySelector;

        public CommonEqualityComparer(Func<T, V> keySelector)
        {
            this._keySelector = keySelector;
        }
        public bool Equals(T x, T y) => object.Equals(_keySelector(x), _keySelector(y));
        public int GetHashCode(T obj) => _keySelector(obj)?.GetHashCode() ?? default;
    }
}
